//
//  MainTabBarViewController.m
//  Ameson
//
//  Created by xmdfst on 2017/1/4.
//  Copyright © 2017年 dofast. All rights reserved.
//

#import "MainTabBarViewController.h"
#import "HomeViewController.h"
#import "WatchViewController.h"
#import "ScoreViewController.h"
#import "RecommendViewController.h"
#import "ForumViewController.h"
#import "YXNavigationController.h"

@interface MainTabBarViewController ()<UITabBarControllerDelegate>

@end

@implementation MainTabBarViewController
-(instancetype)init
{
    self = [super init];
    if (self) {
        self.delegate = self;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UI
-(void)setupUI
{
    UITabBar *tabbar = [UITabBar appearance];
    tabbar.barTintColor = [UIColor whiteColor];
    tabbar.backgroundColor = [UIColor whiteColor];

    
    //改变tabbar 线条颜色
//    CGRect rect = CGRectMake(0, 0, SCREEN_WIDTH, 0.5);
//    UIGraphicsBeginImageContext(rect.size);
//    CGContextRef context = UIGraphicsGetCurrentContext();
//    CGContextSetFillColorWithColor(context,[DFColor dashLight].CGColor);
//    CGContextFillRect(context, rect);
//    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
//    [tabbar setShadowImage:img];
//    [tabbar setBackgroundImage:[[UIImage alloc]init]];
    
    
    NSDictionary* dic_font_normal = [[NSDictionary alloc] initWithObjectsAndKeys:RGBCOLOR(0xa2, 0xa2, 0xa2),NSForegroundColorAttributeName,FONT(11),NSFontAttributeName,nil];
    NSDictionary* dic_font_highted =[[NSDictionary alloc] initWithObjectsAndKeys:[DFColor textBlack],NSForegroundColorAttributeName,FONT(11),NSFontAttributeName,nil];
    
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:dic_font_normal forState:UIControlStateNormal];
    [item setTitleTextAttributes:dic_font_highted forState:UIControlStateSelected];
    
    [self setupChildVC:[[HomeViewController alloc] init] title:@"首页" image:@"shouye_default" selectedImage:@"shouye_seleted"];
    [self setupChildVC:[[WatchViewController alloc] init] title:@"观赛" image:@"guangsai_default" selectedImage:@"guangsai_seleted"];
    [self setupChildVC:[[ScoreViewController alloc] init] title:@"比分" image:@"bifeng_default" selectedImage:@"bifeng_seleted"];
    [self setupChildVC:[[RecommendViewController alloc] init] title:@"推荐" image:@"tuijian_default" selectedImage:@"tuijian_seleted"];
    [self setupChildVC:[[ForumViewController alloc] init] title:@"论坛" image:@"luntan_default" selectedImage:@"luntan_seleted"];
    self.selectedIndex = 0;
}


-(void)setupChildVC:(DFViewController*)vc title:(NSString*)title image:(NSString*)image selectedImage:(NSString *)selectedImage
{
    vc.title = title;
//    if ([title isEqualToString:@"工作台"]) {
//        vc.navigationItem.title = [NSDate weekDayStrOfDate:[NSDate date]];
//        vc.tabBarItem.title = title;
//    }else{
//        
//    }
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    YXNavigationController *navi = [[YXNavigationController alloc]initWithRootViewController:vc];
    [self addChildViewController:navi];
    
}
@end
